package com.ocean.web.controller.product;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.productDict.domain.OAging;
import com.ocean.productDict.service.IOAgingService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 产品时效维护Controller
 *
 * @author ocean
 * @date 2023-01-04
 */
@Controller
@RequestMapping("/product/aging")
public class OAgingController extends BaseController
{
    private String prefix = "product/aging";

    @Autowired
    private IOAgingService oAgingService;

    //@RequiresPermissions("product:aging:view")
    @GetMapping()
    public String aging()
    {
        return prefix + "/list";
    }

    /**
     * 查询产品时效维护列表
     */
    //@RequiresPermissions("product:aging:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OAging oAging)
    {
        startPage();
        List<OAging> list = oAgingService.selectOAgingList(oAging);
        return getDataTable(list);
    }

    /**
     * 导出产品时效维护列表
     */
    //@RequiresPermissions("product:aging:export")
    @Log(title = "产品时效维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OAging oAging)
    {
        List<OAging> list = oAgingService.selectOAgingList(oAging);
        ExcelUtil<OAging> util = new ExcelUtil<OAging>(OAging.class);
        return util.exportExcel(list, "产品时效维护数据");
    }

    /**
     * 新增产品时效维护
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        Map<String,List> map = oAgingService.getCodes();
        mmap.putAll(map);
        return prefix + "/add";
    }

    /**
     * 新增保存产品时效维护
     */
    //@RequiresPermissions("product:aging:add")
    @Log(title = "产品时效维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OAging oAging)
    {
        return toAjax(oAgingService.insertOAging(oAging));
    }

    /**
     * 修改产品时效维护
     */
    //@RequiresPermissions("product:aging:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OAging oAging = oAgingService.selectOAgingById(id);
        mmap.put("oAging", oAging);
        Map<String,List> map = oAgingService.getCodes();
        mmap.putAll(map);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品时效维护
     */
    //@RequiresPermissions("product:aging:edit")
    @Log(title = "产品时效维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OAging oAging)
    {
        return toAjax(oAgingService.updateOAging(oAging));
    }

    /**
     * 删除产品时效维护
     */
    //@RequiresPermissions("product:aging:remove")
    @Log(title = "产品时效维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oAgingService.deleteOAgingByIds(ids));
    }

    /**
     * 产品时效维护详情
     */
    //@RequiresPermissions("product:aging:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        OAging oAging = oAgingService.selectOAgingById(id);
        mmap.put("oAging", oAging);
        return prefix + "/detail";
    }
}
